package cn.enilu.guns.bean.entity.door;


import cn.enilu.guns.bean.entity.system.User;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import cn.enilu.guns.bean.entity.BaseEntity;
import org.hibernate.annotations.Table;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity(name="T_ENTRANCE_GUARD_RULE")
@Table(appliesTo = "t_entrance_guard_rule",comment = "门禁权限")
//@Getter
//@Setter
//@ToString(exclude={"users","doorInfos"})
//@EqualsAndHashCode(exclude={"users","doorInfos"})
@Data
@EntityListeners(AuditingEntityListener.class)
public class EntranceGuardRule extends BaseEntity {

	@JoinColumn(name="time_id", referencedColumnName = "id",  columnDefinition = "BIGINT(19) COMMENT '时段id'")
	@ManyToOne(fetch = FetchType.EAGER)
	private TimeInfo timeInfo;

	@ManyToMany(cascade = CascadeType.PERSIST,fetch = FetchType.LAZY)
	@JoinTable(name = "t_entrance_guard_door", joinColumns = @JoinColumn(name = "ruleId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "doorId", referencedColumnName = "id"))
	@JsonBackReference
	private Set<DoorInfo> doorInfos = new HashSet<>();

	@ManyToMany(cascade = CascadeType.PERSIST,fetch = FetchType.LAZY)
	@JoinTable(name = "t_entrance_gard_user", joinColumns = @JoinColumn(name = "ruleId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "userId", referencedColumnName = "id"))
	@OrderBy("id ASC")
	@JsonBackReference
	private Set<User> users = new HashSet<>();

	/**
	 * 
	 */
	@Column(columnDefinition = " INT(10) COMMENT ''")
	private Integer version;

	/**
	 * 权限名称
	 */
	@Column(columnDefinition = " VARCHAR(64) COMMENT '权限名称'")
	private String ruleName;

	/**
	 * 备注
	 */
	@Column(columnDefinition = " VARCHAR(255) COMMENT '备注'")
	private String remark;

	/**
	 * 时段id
	 */
//	@Column(columnDefinition = " BIGINT(19) COMMENT '时段id'")
//	private Long timeId;

}
